package cn.iocoder.yudao.module.resource.dal.mysql.cosplay;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.resource.controller.admin.cosplay.vo.LmCosplayPageReqVO;
import cn.iocoder.yudao.module.resource.dal.dataobject.cosplay.LmCosplayDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 角色 Mapper
 *
 * @author wgs
 */
@Mapper
public interface LmCosplayMapper extends BaseMapperX<LmCosplayDO> {

    default PageResult<LmCosplayDO> selectPage(LmCosplayPageReqVO reqVO) {
        final LambdaQueryWrapperX<LmCosplayDO> query = new LambdaQueryWrapperX<LmCosplayDO>()
                .likeIfPresent(LmCosplayDO::getName, reqVO.getName())
                .betweenIfPresent(LmCosplayDO::getCreateTime, reqVO.getCreateTime());
        if (CollUtil.isNotEmpty(reqVO.getShowLocation())) {
            for (String location : reqVO.getShowLocation()) {
                query.apply("FIND_IN_SET({0}, show_location)", location);
            }
        }
        query.orderByDesc(LmCosplayDO::getId);
        return selectPage(reqVO, query);
    }

    default void updateFieldNull(LmCosplayDO cosplayDO) {
        LambdaUpdateWrapper<LmCosplayDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(LmCosplayDO::getRoleImageId, cosplayDO.getRoleImageId())
                .set(LmCosplayDO::getRoleIconId, cosplayDO.getRoleIconId())
                .eq(LmCosplayDO::getId, cosplayDO.getId());
        this.update(updateWrapper);
    }

}